package Channel;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import projectjet.Autentification;

public class ChooseChannel {
    private Autentification autentification;
    private BufferedReader in;
    private static List<String> channels = new ArrayList<String>();
    private String channel;
    private static GetChannels getChannel = new GetChannels();
 
    public ChooseChannel(Autentification autentification, BufferedReader in){
        this.autentification =  autentification;
        this.in = in;   
        
    }
    
    public boolean channelChoosed(){
        channels = getChannel.getChannelsFromDataBase();
        autentification.send("Available channels: " + this.channels + ".\nEnter channel where you want to chat: ");
        while(true){
                String channelFromClient = "";

                try {
                        channelFromClient = this.in.readLine();
                } catch (IOException e) {
                        e.printStackTrace();
                }
                for(String room : this.channels){

                        if(channelFromClient.toUpperCase().equals(room)){
                                this.channel = room;
                                return true;
                        }
                }
                autentification.send("Channel " + channelFromClient + " is not exist in this chat. Please, enter channel where you want to chat again:");
        }
     }
    
    public String getChannel(){
        return channel;
    }
}
